<form action="<?php echo U('Admin/Goods/Category/sort');?>" method="post" id="category-sort" class="_ajaxSubmit">
    <?php if($pid):?>
    <div class="col-xs-12 col-md-12 col-lg-12 status-bar">
        <button type="submit" class="btn btn-success radius-none">排序</button>
        <a href="javascript:;" data-ppid="<?php echo $ppid?>" class="btn btn-info radius-none go-prev">返回上一级</a>
    </div>
    <?php else:?>
    <div class="col-xs-12 col-md-12 col-lg-12 status-bar">
        <button type="submit" class="btn btn-success radius-none">排序</button>
    </div>
    <?php endif;?>
    <table class="table table-hover">
        <tr>
            <th>排序</th>
            <th>分类ID</th>
            <th>分类名</th>
            <th>操作</th>
        </tr>
        <?php foreach($data as $k => $v):?>
        <tr>
            <td><input type="text" name="<?php echo $v[id]?>" value="<?php echo $v['sort']?>" class="text-center _data" style="width: 40px"></td>
            <td><?php echo $v['id']?></td>
            <td>
                <?php if($v['child']):?>

                <a href="javascript:;" data-src="<?php echo U('Admin/Goods/Category/lists')?>" data-id="<?php echo $v['id']?>" class="load-child"><?php echo $v['name']?></a>

                <?php else:?>
                    <?php echo $v['name']?>
                <?php endif;?>
            </td>
            <td>
                <a href="javascript:;" data-src="<?php echo U('Admin/Goods/Category/update')?>" data-data='{"pid":<?php echo $v['pid']?>,"id":<?php echo $v['id']?>}' class="btn btn-primary btn-xs update">修改</a>
                <?php if(!$v['child']):?>
                    <a href="javascript:;" data-msg="确定删除吗?" data-id="delete" data-src="<?php echo U('Admin/Goods/Category/delete')?>" data-data="<?php echo $v['id']?>" class="btn btn-danger btn-xs _ajaxNote">删除</a>
                <?php else:?>
                    <a href="javascript:;" data-src="<?php echo U('Admin/Goods/Category/lists')?>" data-id="<?php echo $v['id']?>" class="btn btn-default btn-xs load-child">查看下级</a>
                <?php endif;?>
            </td>
        </tr>
        <?php endforeach;?>
    </table>
</form>
<script>

    $(function(){
        //修改规则
        $('.update').unbind('click');
        $('.update').click(function(){

            var src = $(this).data('src');
            var data = $(this).data('data');

            showMessage('',false,src,{'data':data},1);

        });
        //加载子规则列表
        $('.load-child').unbind('click');
        $('.load-child').click(function(){

            var pid = $(this).data('id');

            var url = $(this).data('src');

            showMessage('',false,url,{'pid' : pid},1);


        })
        <?php if($pid):?>
        /*
         * 返回上一级
         */
        $('.go-prev').unbind('click');
        $('.go-prev').click(function(){

            var obj = {}

            obj.url = '<?php echo U('/Admin/Goods/Category/lists');?>';

            obj.data = {pid:<?php echo $ppid ? $ppid : 0 ;?>};

            showMessage(obj);

        });
        <?php endif;?>
    });
    //排序异步请求回调
    function ajaxRequestCallback(result,id,_this)
    {

        switch(id){

            case 'category-sort':

                showMessage(result.msg,result.code,'<?php echo U("/Admin/Goods/Category/lists")?>',{pid:'<?php echo $pid?$pid:0;?>'},2000);

                break;


            case 'delete':

                _delete(result, _this);

                break;

        }


    }
    //删除回调
    function _delete(res, _this){

        if(res.code == 200){

            layer.msg(res.msg,{time:2000});

            //删除当前节点
            _this
                .parent()
                .parent()
                .fadeOut(2000,function(){

                    $(this).remove();

                })

        }else{

            layer.msg(res.msg,function(){});

        }

    }
</script>